package 力扣日常刷题.木23一月.第01天301;

/**
 * @author 帅小伙
 * @date 2022/3/1
 * @description
 */
public class Demo10二叉搜索树的后序遍历 {


    public boolean verifyPostorder(int[] postorder) {
        return recur(postorder,0,postorder.length - 1);
    }

    public boolean recur(int[] postorder, int l, int r) {
        if(l >= r) return true;
        int p = l;
        while(postorder[p] < postorder[r]) p++;
        int m = p;
        while(postorder[p] > postorder[r]) p++;
        return p == r && recur(postorder,l,m - 1) && recur(postorder,m,r - 1);
    }

}
